package models;

import java.io.Serializable;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

/**
 * @author luong
 * this entity is mapped to the Balise table
 */
@Entity 
@Table (name="Balise")
public class HibernateTags implements Serializable{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Id @GeneratedValue
	@Column (name="TAG_ID")
	private int tag_id;
	
	@Column
	private String typeB;
	
	@Column
	private String xPath;
	
	@Column
	private int taille;
	
	@OneToOne(cascade = CascadeType.REFRESH)
	@JoinColumn(name = "tagFather", referencedColumnName = "TAG_ID") 
	private HibernateTags tagFather;
	
	@ManyToOne(cascade = CascadeType.REFRESH)
	@JoinColumn (name="CONTAINER", referencedColumnName = "DOC_ID")
	private HibernateDocument docID;
	
	@OneToMany (cascade = CascadeType.REFRESH)
	@JoinColumn(name="CONTAINER_TAG_OCC")
	private Set<HibernateOccurence> occList;
	
	@OneToMany (cascade = CascadeType.REFRESH)
	@JoinColumn(name="CONTAINER_TAG_POS")
	private Set<HibernatePosition> positionList;
	
	public HibernateTags() {}

	public int getId() {
		return tag_id;
	}

	public void setId(int id) {
		this.tag_id = id;
	}

	public String getxPath() {
		return xPath;
	}

	public void setxPath(String xPath) {
		this.xPath = xPath;
	}

	public HibernateDocument getDocID() {
		return docID;
	}

	public void setDocID(HibernateDocument docID) {
		this.docID = docID;
	}

	public Set<HibernateOccurence> getOccList() {
		return occList;
	}

	public void setOccList(Set<HibernateOccurence> occList) {
		this.occList = occList;
	}

	public String getTypeB() {
		return typeB;
	}

	public void setTypeB(String typeB) {
		this.typeB = typeB;
	}
	
	public int getTaille() {
		return taille;
	}

	public void setTaille(int taille) {
		this.taille = taille;
	}
	
	public HibernateTags getTagFather() {
		return tagFather;
	}

	public void setTagFather(HibernateTags tagFather) {
		this.tagFather = tagFather;
	}

	public Set<HibernatePosition> getPositionList() {
		return positionList;
	}

	public void setPositionList(Set<HibernatePosition> positionList) {
		this.positionList = positionList;
	}
	
	public HibernateTags getContainer(String typeB){
		HibernateTags t = null;
		if(this.typeB.equals(typeB)){
			t = this;
		}else{
			t = this.getTagFather().getContainer(typeB);
		}
		return t;
	}
	
}
